package com.wsz.cloud.core.controller;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RestController;

import com.wsz.cloud.core.entity.UserInfo;
import com.wsz.cloud.core.service.UserInfoService;

@RestController // @RestController 其实这个注解是组合注解，等价于Controller和ResponseBody方法直接以字符串的方式返回出去，不能跳转了
public class UserInfoController {

	@Autowired
	private UserInfoService userInfoService;
	
	@GetMapping("/admin")
	public String testIgnored() {
		return "Ignored Success";
	}
	
	@GetMapping("/simple/{id}") // @GetMapping等价于 RequestMapping(value="/simple/{id}" ,method=RequestMethod.POST)
	public UserInfo findUserInfoById(@PathVariable Long id) {
		return userInfoService.findOne(id);
	}
	
	@PostMapping("/userInfo")
	public UserInfo getUserInfoJson(@RequestBody UserInfo userInfo) {
		System.out.println(userInfo);
		return userInfo;
	}
	
	@GetMapping("/list")
	public List<UserInfo> getUserList() {
		return userInfoService.getUserList();
	}
	
	@GetMapping("/arr")
	public UserInfo[] getUserArr() {
		List<UserInfo> userList = userInfoService.getUserList();
		UserInfo[] userInfos = new UserInfo[userList.size()];
		int i = 0;
		for (UserInfo userInfo : userList) {
			userInfos[i++] = userInfo;
		}
		return userInfos;
	}	
}
